﻿# -*- coding: utf-8 -*-
#import os, sys
import array
# "¶",   "d",    "[k",  "x",  "T",  "t",   "M+", "<+", "Q",  ";",    "j",   "u",
class krutitounicode:
	array_one_length=0

	array_one = ["å",  "ƒ",  "„",   "…",   "†",   "‡",   "ˆ",   "‰",   "Š",   "‹", "~ "]


	array_one.extend(["Ùk", "Ù", "ä", "–", "—"])     

	array_one.extend(["à",   "á",    "â",   "ã",   "ºz",  "º",   "í", "#k", "#", "=",  "«"])
	array_one.extend(["Nî",   "Vî",    "Bî",   "Mî",   "<î", "|", "K", "#"])
	array_one.extend(["J",   "Vª",   "Mª",  "<ªª",  "Nª",   "Ø",  "Ý",   "æ", "ç", "Á", "xz", "#", ":"])

	array_one.extend(["vks",  "vkS",  "vk",    "v",  "b±", "Ã",  "bZ",  "b",  "m",  "Å",  ",s",  ",",   "_"])

	array_one.extend(["ô",  "d", "Dk", "D", "[k", "[", "x","Xk", "X", "Ä", "?k", "?",   "³"])
	array_one.extend(["pkS",  "p", "Pk", "P",  "N",  "t", "Tk", "T",  ">", "÷", "¥"])

	array_one.extend(["ê",  "ë",   "V",  "B",   "ì",   "ï", "M+", "<+", "M",  "<", ".k", "."])
	array_one.extend(["r",  "Rk", "R",   "Fk", "F",  ")", "n", "/k", "èk",  "/", "Ë", "è", "u", "Uk", "U"])

	array_one.extend(["i",  "Ik", "I",   "Q",    "¶",  "c", "Ck",  "C",  "Hk",  "H", "e", "Ek",  "E"]) 	
	array_one.extend([";",  "¸",   "j",    "y", "Yk",  "Y",  "G",  "o", "Ok", "O",	"'k", "'",   "\"k",  "\"",  "l", "Lk",  "L"]) 
	array_one.extend(["g", 	"È", "z",	"Ì", "Í", "Î",  "Ï",  "Ñ",  "Ò",  "Ó",  "Ô",   "Ö",  "Ø"])
	array_one.extend(["Ù", "Ü", "v‚",    "‚",    "ks",   "kS",   "k",  "h",    "q",   "w",   "`",    "s",    "S",	"a",    "¡",    "%"])
	array_one.extend(["W",  "•", "·", "∙", "·", "~j",  "~", "\\", "^", "*",  "Þ", "ß", "(", "¼", "½", "¿", "À", "¾", "A", "-", "&", "&", "Œ", "]","+"])

	array_two = ["०",  "१",  "२",  "३",     "४",   "५",  "६",   "७",   "८",   "९",  "् "]

	# "फ़्",  "क़",  "ख़",  "ग़", "ज़्", "ज़",  "ड़",  "ढ़",   "फ़",  "य़",  "ऱ",  "ऩ",    # one-byte nukta varNas
	array_two.extend(["त्त", "त्त्", "क्त",  "दृ",  "कृ"])

	array_two.extend(["ह्न",  "ह्य",  "हृ",  "ह्म",  "ह्र",  "ह्",   "द्द",  "क्ष", "क्ष्", "त्र", "त्र्"]) 
	array_two.extend(["छ्य",  "ट्य",  "ठ्य",  "ड्य",  "ढ्य", "द्य", "ज्ञ", "द्व"])
	array_two.extend(["श्र",  "ट्र",    "ड्र",    "ढ्र",    "छ्र",   "क्र",  "फ्र",  "द्र",   "प्र", "प्र",  "ग्र", "रु",  "रू"])

	array_two.extend(["ओ",  "औ",  "आ",   "अ", "ईं", "ई",  "ई",   "इ",  "उ",   "ऊ",  "ऐ",  "ए", "ऋ"])

	array_two.extend(["क्क", "क", "क", "क्", "ख", "ख्", "ग", "ग", "ग्", "घ", "घ", "घ्", "ङ"])
	array_two.extend(["चै",  "च", "च", "च्", "छ", "ज", "ज", "ज्",  "झ",  "झ्", "ञ"])

	array_two.extend(["ट्ट",   "ट्ठ",   "ट",   "ठ",   "ड्ड",   "ड्ढ",  "ड़", "ढ़", "ड","ढ", "ण", "ण्"])
	array_two.extend(["त", "त", "त्", "थ", "थ्",  "द्ध",  "द", "ध", "ध", "ध्", "ध्", "ध्", "न", "न", "न्"])   

	array_two.extend(["प", "प", "प्",  "फ", "फ्",  "ब", "ब", "ब्",  "भ", "भ्",  "म",  "म", "म्"])
	array_two.extend(["य", "य्",  "र", "ल", "ल", "ल्",  "ळ",  "व", "व", "व्"])
	array_two.extend(["श", "श्",  "ष", "ष्", "स", "स", "स्", "ह"])

	array_two.extend(["ीं", "्र","द्द", "ट्ट","ट्ठ","ड्ड","कृ","भ","्य","ड्ढ","झ्","क्र","त्त्","श्"])

	array_two.extend(["ऑ",   "ॉ",  "ो",   "ौ",   "ा",   "ी",   "ु",   "ू",   "ृ",   "े",   "ै"])
	array_two.extend(["ं",   "ँ",   "ः",   "ॅ",  "ऽ", "ऽ", "ऽ", "ऽ", "्र",  "्", "?"])
	array_two.extend(["‘",   "’",   "“",   "”",  ";",  "(",    ")",   "#",    "#",   "=", "।", ".", "-",  "µ", "॰", ",","़" ])

	# The following two characters are to be replaced through proper checking of locations:
	# "Z" )
	# "र्" (reph) 

	# "f" )
	# "ि"  


	array_one_length = len(array_one)
	
	  
	def convert_to_unicode(self,modified_substring):
		modified_substring=modified_substring.encode('utf-8')
		origtext = modified_substring
		
		#****************************************************************************************
		#  Break the long text into small bunches of max. max_text_size  characters each.
		#****************************************************************************************
		text_size = len(modified_substring)

		processed_text = ''  #blank

		sthiti1 = 0
		sthiti2 = 0 
		chale_chalo = 1 
		 
		max_text_size = 6000

		while ( chale_chalo == 1 ):
			sthiti1 = sthiti2 

			if ( sthiti2 < ( text_size - max_text_size ) ):  
		  
				sthiti2 +=  max_text_size 
				while (modified_substring[sthiti2 ] != ' '):
					sthiti2=sthiti2-1
		  
			else:  
				 sthiti2 = text_size    
				 chale_chalo = 0 
			#print sthiti1,sthiti2,origtext
			modified_substring = origtext[sthiti1:sthiti2]  
			#print repr(modified_substring)
			try:
				#print modified_substring
				modified_substring=self.Replace_Symbols(modified_substring)
			except:
				print repr(modified_substring)+" after replace symbols"

			processed_text += modified_substring 

		return processed_text

	# --------------------------------------------------


	def Replace_Symbols(self,modified_substring):


		#print modified_substring+"haha haha ha"
		#print self.array_one_length
		#substitute array_two elements in place of corresponding array_one elements
		#modified_substring

		if modified_substring:  # if stringto be converted is non-blank then no need of any processing.
		
			for input_symbol_idx  in xrange(0,self.array_one_length):


				#print array_one_length
				idx = 0    # index of the symbol being searched for replacement
				#print str(input_symbol_idx)+" input symbol idx"
				#x=self.array_one[input_symbol_idx]
						
				#print x

				#print repr(self.array_one)
				while (idx != -1 ): #whie-00
					
						#print repr(modified_substring)+" --hahaha haha ha"
						#print modified_substring
						#print x.decode('ascii')+" encoding ascii"
						#print x.decode('utf-8')+" encoding utf-8"

						#print x.decode('iso-8859-1')+" encoding utf-16"
						x=self.array_one[ input_symbol_idx ]
						y=self.array_two[input_symbol_idx]
						#print x
						#print y
						try:
							#print x+" hi hi x"
							modified_substring = modified_substring.replace( x, y)
							#print modified_substring+"haha haha ha"
							idx = modified_substring.find(x)
						except Exception as inst:
							print inst
							print type(inst)
							idx=-1
							#idx=-1




			#**********************************************************************************
			# Code for Replacing five Special glyphs
			#**********************************************************************************
			#
			#**********************************************************************************
			# Glyp1: Æ
			# code for replacing "f" with "ि" and correcting its position too. (moving it one position forward)
			#**********************************************************************************"""

			modified_substring = modified_substring.replace( "Æ" , "र्f" ) # at some places  Æ  is  used eg  in "धार्मिक".

			position_of_i = modified_substring.find( "f" )
			#print "position of i is"+str(position_of_i)+repr(modified_substring)

			while ( position_of_i != -1 ):

				charecter_next_to_i = modified_substring[position_of_i + 2 ] # in python yu have \xe0 after every byte
				charecter_to_be_replaced = "f" + charecter_next_to_i
				#print repr(modified_substring[1])+"character next to i"
				#print repr(modified_substring)+" before character to be replaced"
				modified_substring = modified_substring.replace( charecter_to_be_replaced , charecter_next_to_i + "ि" ) 
				#print repr(modified_substring)+" after character to be replaced"
				position_of_i = modified_substring.find( "f",position_of_i + 2 ) #search for i ahead of the current position.
				#print "position of i is now"+str(position_of_i)



			"""**********************************************************************************
			# Glyph2 & Glyph3: Ç  É
			# code for replacing "fa" with "िं"  and correcting its position too.(moving it two positions forward)
			#**********************************************************************************"""

			modified_substring = modified_substring.replace( "Ç" , "fa" ) #at some places  Ç  is  used eg  in "किंकर".
			modified_substring = modified_substring.replace( "É" , "र्fa" ) # at some places  É  is  used eg  in "शर्मिंदा"
			try:
				position_of_i = modified_substring.find( "fa" )

				while ( position_of_i != -1 ):  #while-02
				#
					charecter_next_to_ip2 = modified_substring[position_of_i + 6:position_of_i + 9 ]
					print repr(charecter_next_to_ip2)+str(position_of_i)+repr(modified_substring)
					charecter_to_be_replaced = "fa" + charecter_next_to_ip2
					modified_substring = modified_substring.replace( charecter_to_be_replaced , charecter_next_to_ip2 + "िं" ) 
					position_of_i = modified_substring.find( "fa",position_of_i + 6 ) # search for i ahead of the current position.
			except Exception as inst:
				print inst
				print "error"

			# # end of while-02 loop

			#**********************************************************************************
			# Glyph4: Ê
			#**********************************************************************************

			modified_substring = modified_substring.replace( "Ê" , "ीZ" ) # at some places  Ê  is  used eg  in "शर्मीला".
			#**********************************************************************************
			# Glyph5: ±
			#**********************************************************************************

			modified_substring = modified_substring.replace( "±" , "Zं" ) ; # at some places  ±  is  used eg  in "कर्कंधु,पूर्णांक".
			#**********************************************************************************
			# End of Code for Replacing five Special glyphs
			#**********************************************************************************

			# following loop to eliminate 'chhotee ee kee maatraa' on half-letters as a result of above transformation.

			position_of_wrong_ee = modified_substring.find( "ि्" ) 

			while ( position_of_wrong_ee != -1 ):  #while-03

			
				consonent_next_to_wrong_ee = modified_substring[ position_of_wrong_ee +3]
				charecter_to_be_replaced = "ि्" + consonent_next_to_wrong_ee 
				modified_substring = modified_substring.replace( charecter_to_be_replaced , "्" + consonent_next_to_wrong_ee + "ि" ) 
				position_of_wrong_ee = modified_substring.find( "ि्" , position_of_wrong_ee + 3 ) # search for 'wrong ee' ahead of the current position. 

				# # end of while-03 loop


			# Eliminating reph "Z" and putting 'half - r' at proper position for this.
			set_of_matras = "ा ि ी ु ू ृ े ै ो ौ ं : ँ ॅ" 
			print repr(set_of_matras)+" matras"
			position_of_R = modified_substring.find( "Z" )
			print repr(modified_substring)+"  Z"+str(position_of_R)
			decrement=3;
			try:
				while ( position_of_R > 0 ):  # while-04
				
					probable_position_of_half_r = position_of_R - decrement
					#decrement+=1
					charecter_at_probable_position_of_half_r = modified_substring[probable_position_of_half_r:probable_position_of_half_r+decrement ]

					#print repr(modified_substring[probable_position_of_half_r:probable_position_of_half_r+decrement ])+str(set_of_matras.find( charecter_at_probable_position_of_half_r ))+' iteration R'
					# trying to find non-maatra position left to current O (ie, half -r).
			
					while set_of_matras.find( charecter_at_probable_position_of_half_r )!= -1:  # while-05
					
						probable_position_of_half_r = probable_position_of_half_r - 3 ;
						charecter_at_probable_position_of_half_r = modified_substring[probable_position_of_half_r :probable_position_of_half_r+3] 
						#print repr(modified_substring[probable_position_of_half_r:probable_position_of_half_r+3])+' iteration r'

					


					charecter_to_be_replaced = modified_substring[probable_position_of_half_r :position_of_R] 
					#print repr(charecter_to_be_replaced)+"kya hua"
					new_replacement_string = "र्" + charecter_to_be_replaced 
					charecter_to_be_replaced = charecter_to_be_replaced + "Z" 
					modified_substring = modified_substring.replace( charecter_to_be_replaced , new_replacement_string ) 
					position_of_R = modified_substring.index( "Z" )
					#print "iteration "+repr(modified_substring)+str(position_of_R)
			except Exception as inst:
					print inst
		return modified_substring

#converter=krutitounicode()
#conv_str=converter.convert_to_unicode("Jh jktsUnz dqek xqIrk")
#print conv_str
#print conv_str.encode("utf-8")









import types, string, re

"""
Unserialize class for the PHP serialization format.

@version v0.4 BETA
@author Scott Hurring; scott at hurring dot com
@copyright Copyright (c) 2005 Scott Hurring
@license http://opensource.org/licenses/gpl-license.php GNU Public License
$Id: PHPUnserialize.py,v 1.1 2006/01/08 21:53:19 shurring Exp $

Most recent version can be found at:
http://hurring.com/code/python/phpserialize/

Usage:
# Create an instance of the unserialize engine
u = PHPUnserialize()
# unserialize some string into python data
data = u.unserialize(serialized_string)

Please see README.txt for more information.
"""

class PHPUnserialize(object):
	"""
	Class to unserialize something from the PHP Serialize format.

	Usage:
	u = PHPUnserialize()
	data = u.unserialize(serialized_string)
	"""

	def __init__(self):
		pass

	def session_decode(self, data):
		"""Thanks to Ken Restivo for suggesting the addition
		of session_encode
		"""
		session = {}
		while len(data) > 0:
			m = re.match('^(\w+)\|', data)
			if m:
				key = m.group(1)
				offset = len(key)+1
				(dtype, dataoffset, value) = self._unserialize(data, offset)
				offset = offset + dataoffset
				data = data[offset:]
				session[key] = value
			else:
				# No more stuff to decode 
				return session
		
		return session
		
	def unserialize(self, data):
		return self._unserialize(data, 0)[2]

	def _unserialize(self, data, offset=0):
		"""
		Find the next token and unserialize it.
		Recurse on array.

		offset = raw offset from start of data
		
		return (type, offset, value)
		"""

		buf = []
		dtype = string.lower(data[offset:offset+1])

		#print "# dtype =", dtype

		# 't:' = 2 chars
		dataoffset = offset + 2
		typeconvert = lambda x : x
		chars = datalength = 0

 		# int => Integer
		if dtype == 'i':
			typeconvert = lambda x : int(x)
			(chars, readdata) = self.read_until(data, dataoffset, ';')
			# +1 for end semicolon
			dataoffset += chars + 1

 		# bool => Boolean
		elif dtype == 'b':
			typeconvert = lambda x : (int(x) == 1)
			(chars, readdata) = self.read_until(data, dataoffset, ';')
			# +1 for end semicolon
			dataoffset += chars + 1

		# double => Floating Point
		elif dtype == 'd':
			typeconvert = lambda x : float(x)
			(chars, readdata) = self.read_until(data, dataoffset, ';')
			# +1 for end semicolon
			dataoffset += chars + 1

		# n => None
		elif dtype == 'n':
			readdata = None

		# s => String
		elif dtype == 's':
			(chars, stringlength) = self.read_until(data, dataoffset, ':')
			# +2 for colons around length field
			dataoffset += chars + 2

			# +1 for start quote
			(chars, readdata) = self.read_chars(data, dataoffset+1, int(stringlength))
			# +2 for endquote semicolon
			dataoffset += chars + 2

			if chars != int(stringlength) != int(readdata):
				raise Exception("String length mismatch")

		# array => Dict
		# If you originally serialized a Tuple or List, it will
		# be unserialized as a Dict.  PHP doesn't have tuples or lists,
		# only arrays - so everything has to get converted into an array
		# when serializing and the original type of the array is lost
		elif dtype == 'a':
			readdata = {}

			# How many keys does this list have?
			(chars, keys) = self.read_until(data, dataoffset, ':')
			# +2 for colons around length field
			dataoffset += chars + 2

			# Loop through and fetch this number of key/value pairs
			for i in range(0, int(keys)):
				# Read the key
				(ktype, kchars, key) = self._unserialize(data, dataoffset)
				dataoffset += kchars
				#print "Key(%i) = (%s, %i, %s) %i" % (i, ktype, kchars, key, dataoffset)

				# Read value of the key
				(vtype, vchars, value) = self._unserialize(data, dataoffset)
				dataoffset += vchars
				#print "Value(%i) = (%s, %i, %s) %i" % (i, vtype, vchars, value, dataoffset)

				# Set the list element
				readdata[key] = value

				# +1 for end semicolon
			dataoffset += 1
			#chars = int(dataoffset) - start

		# I don't know how to unserialize this
		else:
			raise Exception("Unknown / Unhandled data type (%s)!" % dtype)


		return (dtype, dataoffset-offset, typeconvert(readdata))

	def read_until(self, data, offset, stopchar):
		"""
		Read from data[offset] until you encounter some char 'stopchar'.
		"""
		buf = []
		char = data[offset:offset+1]
		i = 2
		while char != stopchar:
			# Consumed all the characters and havent found ';'
			if i+offset > len(data):
				raise Exception("Invalid")
			buf.append(char)
			char = data[offset+(i-1):offset+i]
			i += 1

		# (chars_read, data)
		return (len(buf), "".join(buf))

	def read_chars(self, data, offset, length):
		"""
		Read 'length' number of chars from data[offset].
		"""
		buf = []
		# Account for the starting quote char
		#offset += 1
		for i in range(0, length):
			char = data[offset+(i-1):offset+i]
			buf.append(char)

		# (chars_read, data)
		return (len(buf), "".join(buf))



def _parse_row(book, sheet, row_index, date_as_tuple):
        """ Sanitize incoming excel data """
        # Data Type Codes:
        #  EMPTY 0
        #  TEXT 1 a Unicode string 
        #  NUMBER 2 float 
        #  DATE 3 float 
        #  BOOLEAN 4 int; 1 means TRUE, 0 means FALSE 
        #  ERROR 5 
        values = []
        for type, value in zip(
                sheet.row_types(row_index), sheet.row_values(row_index)):
            if type == 3:
                 datetuple = xlrd.xldate_as_tuple(value, book.datemode)
                 if date_as_tuple:
                    value = datetuple
                 else:
                    # time only no date component
                    if datetuple[0] == 0 and datetuple[1] == 0 and \
                       datetuple[2] == 0: 
                        value = "%02d:%02d:%02d" % datetuple[3:]
                    # date only, no time
                    elif datetuple[3] == 0 and datetuple[4] == 0 and \
                         datetuple[5] == 0:
                        value = "%04d/%02d/%02d" % datetuple[:3]
                    else: # full date
                        value = "%04d/%02d/%02d %02d:%02d:%02d" % datetuple
            
			
            values.append(value)
        return values



# Creating nodes in Drupal 6 via the Services module using
# Python and XML-RPC.
#
# To use this, get and install the Services module from
#    http://drupal.org/project/services
#
# Enable the XMLRPC Server module, the System Service module and the
# Node Service module at least.
#
#
# Note that this is intended to demo quick importing of data from other
# systems. It makes no use of authentication, in fact you need to enable
# various permissions for anonymous users to be able to use it.
# Enable things like 'administer nodes', 'create page content',
# 'create url aliases' and 'administer url aliases'.
#
#myfield=resulting.result["field_myfield"][0].value;

#and when writing that note back:

#nodeObject.field_myfield=[{format: "3", value: myfield}];

# You should remember, therefore, to DISABLE them before you go live
# with a production site!
#
# This assumes you have 'Use sessid' but not 'Use keys' enabled in the
# Services settings at http://yoursite/admin/build/services/settings.

import xmlrpclib
import datetime,time
#import time

import hmac, string, random, hashlib, pprint,sys

# Put the URL for your Service in here. See admin/build/services.
s = xmlrpclib.Server('http://localhost/d614/services/xmlrpc',None,None,False,False,False)
"""
print s.system.methodSignature('system.connect')
class node:
    # You need to set uid and username appropriately for your site if you don't want
    # everything to be posted by Anonymous.
    def __init__(self, title, body,ntype='test1'):
       self.title = title
       self.body = body
       self.type = ntype
"""

conn=s.system.connect()
api = 'ed7182d8b056d4bd1cd078ff016352d5'
url = 'myurl'
user = "admin"
password = "admin"
domain = "localhost"
#drupal = xmlrpclib.ServerProxy(url)
#session = drupal.system.connect()
timestamp = str(int(time.mktime(time.localtime())))
nonce = "".join(random.sample(string.letters+string.digits, 10))
hashMap = hmac.new(api, "%s;%s;%s;%s" % (timestamp, domain, nonce, "user.login"), hashlib.sha256)
#print repr(conn['sessid'])
#print repr(conn['user'])
#new_node = { 'type': 'test1',
#'field_field1': values[1],
#    'field_field2': values[2]                 }
#n=node('Hi','HI I am doing')
#excelfile=s.system.getVariable('ed7182d8b056d4bd1cd078ff016352d5','localhost',timestamp,nonce,conn['sessid'],'excel_uploaded_file','c:/test.xls');
#excelfileformat = s.system.getVariable('ed7182d8b056d4bd1cd078ff016352d5','localhost',timestamp,nonce,conn['sessid'],'node_type_format_excel','haa');
excelfile=s.system.getVariable(conn['sessid'],'excel_uploaded_file','c:/test.xls');
excelfileformat = s.system.getVariable(conn['sessid'],'node_type_format_excel','haa');
converttounicode = s.system.getVariable(conn['sessid'],'converttounicode','haa');
#converter.convert_to_unicode("Jh jktsUnz dqek xqIrk")
unicodeconverter=krutitounicode()
#conv_str=converter.convert_to_unicode("Jh jktsUnz dqek xqIrk")
#print conv_str
#print conv_str.encode("utf-8")

ux = PHPUnserialize()
	# unserialize some string into python data
#print "hi "+excelfileformat
python_data = ux.unserialize(excelfileformat)
row_begin=int(python_data['row_begin'])
row_end=int(python_data['row_end'])
node_type=python_data['type']
del python_data['type']
del python_data['row_begin']
del python_data['row_end']
#del python_data['excel_file']
now=datetime.datetime.now()
nowx=str(now)

#print python_data('tehsil_name')
sess1=s.user.login(conn['sessid'],'services','services');
print "new session id is"+sess1['sessid']
from xlrd import cellname, cellnameabs, colname ,open_workbook 
book = open_workbook(excelfile)
s1=book.sheet_by_index(0) 
for row_index in range(1,169): 
 values = _parse_row(book,s1,row_index,'true') 
 #print row_index, values
 #values[0]
 #print row_index
 #value
 new_node = { 'type': node_type,'uid':sess1['user']['uid']}
 prevvalues=[]
 for  k,v in python_data.iteritems():
    
   
   try:
	 #print k, v, repr(values[int(v)-1])
	 if v!='_excel_import_gen':
		if values[int(v)-1]=='':
			try:
				values[int(v)-1]=prevvalues[int(v)-1]
			except:
				pass
		if (converttounicode):
			try:
				#print "to be converted: "+values[int(v)-1]
				value=unicodeconverter.convert_to_unicode(values[int(v)-1])
				#print "converted: "+repr(unicodeconverter.convert_to_unicode(values[int(v)-1]))
				
				#print repr(value)
			except Exception as inst:
				print inst
				value=values[int(v)-1]
		else:
			value=values[int(v)-1]
	 new_node[k]= [{'format': "3", 'value': value}]   
   except ValueError:
	new_node[k]= [{'format': "3", 'value': v}]
		
 #print row_index 
 #print new_node
 prevvalues=values           
 s.node.save(sess1['sessid'],new_node)



